package com.baozun.houji.order.network

import com.baozhun.mall.common.model.bean.*
import com.baozhun.mall.common.network.NetworkApi
import com.baozun.houji.order.model.bean.*
import com.baozun.houji.order.model.request.RefundReqBean
import com.baozun.houji.order.model.bean.LogisticsCompanyInfoBean
import com.baozun.houji.order.model.bean.RefundDetailBean
import com.baozun.houji.order.model.bean.RefundInfoBean
import com.baozun.houji.order.model.bean.RefundReasonBean
import com.common.pay.PayParamsBean
import retrofit2.http.*

/**
 * @Title：订单ApiService
 * @Description：
 * @Author：xuefeng.zhu
 * @Since：2022/11/4
 * @Version：1.0.0
 */
interface OrderApiService {

    /**
     *
     * 获取订单列表数据
     */
    @GET("order/list")
    suspend fun getOrderListData(
        @Query("status") status: Int?,
        @Query("search") search: String?,
        @Query("page") page: Int
    ): ApiResponse<ApiPagerResponse<ArrayList<OrderInfoBean>>>


    /**
     *
     * 获取售后订单列表数据
     */
    @GET("after-sale/list")
    suspend fun getAfterSaleList(
        @Query("page") page: Int
    ): ApiResponse<ApiPagerResponse<ArrayList<OrderInfoBean>>>


    /**
     *
     * 取消订单
     */
    @GET("order/cancel")
    suspend fun cancelOrder(@Query("order_no") order_no: String): ApiResponse<Any?>

    /**
     *
     * 订单支付
     */
    @GET("order/pay")
    suspend fun orderPay(@Query("order_no") order_no: String, @Query("pay_type") pay_type: String): ApiResponse<PayParamsBean>

    /**
     *
     * 确认收货
     */
    @GET("order/confirm")
    suspend fun finishOrder(@Query("order_no") order_no: String): ApiResponse<Any?>

    /**
     *
     * 删除订单
     */
    @GET("order/delete")
    suspend fun deleteOrder(@Query("order_no") order_no: String): ApiResponse<Any?>

    /**
     *
     * 獲取售後原因
     */
    @GET("after-sale/reasons")
    suspend fun getRefundReason(@Query("type") type: Int): ApiResponse<MutableList<RefundReasonBean>>

    /**
     *
     * 獲取售後详情信息
     */
    @GET("after-sale/detail")
    suspend fun getRefundDetail(@Query("after_sale_no") afterSaleNo: String): ApiResponse<RefundDetailBean>

    /**
     *
     * 获取退款信息
     */
    @GET("after-sale/apply-info")
    suspend fun getRefundInfo(@Query("order_no") orderId: String): ApiResponse<RefundInfoBean>

    /**
     *
     * 获取物流公司
     */
    @GET("after-sale/express")
    suspend fun getLogisticsCompany(): ApiResponse<ArrayList<LogisticsCompanyInfoBean>>

    /**
     *
     * 获取订单物流信息
     */
    @GET("order/express-list")
    suspend fun getLogisticsInfo(@Query("order_no") orderId: String): ApiResponse<ExpressInfoBean?>

    /**
     *
     * 获取售后物流信息
     */
    @GET("after-sale/express-list")
    suspend fun getRefundLogisticsInfo(@Query("after_sale_no") afterSaleNo: String): ApiResponse<ExpressInfoBean?>

    /**
     *
     * 提交退款申请
     */
    @POST("after-sale/apply")
    suspend fun applyRefund(@Body refundReqBean: RefundReqBean): ApiResponse<String>

    /**
     *
     * 取消退款操作
     */
    @GET("after-sale/cancel")
    suspend fun cancelRefund(@Query("after_sale_no") afterSaleNo: String): ApiResponse<Any?>

    /**
     *
     * 提交物流信息
     */
    @POST("after-sale/delivery")
    @FormUrlEncoded
    suspend fun delivery(@Field("after_sale_no") afterSaleNo: String, @Field("express_company_code") expressCompanyCode: String, @Field("express_no") expressNo: String): ApiResponse<Any?>

    /**
     *
     * 填写退货信息
     */
    @POST("after-sale/return-goods")
    suspend fun submitRefundInfo(@Body params: RefundInfoReqBean): ApiResponse<String>

    /**
     *
     * 获取订单详情数据
     */
    @GET("order/detail")
    suspend fun getOrderDetailData(@Query("order_no") order_no: String): ApiResponse<OrderDetailBean>


    /**
     * 搜索订单
     */
    @GET("order/list")
    suspend fun searchOrder(
        @Query("kwyWord") kwyWord: String,
    ): ApiResponse<ApiPagerResponse<ArrayList<OrderInfoBean>>>

}

/**
 * 双重校验锁式-单例 封装NetApiService 方便直接快速调用简单的接口
 */
val orderApiService: OrderApiService by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) {
    NetworkApi.INSTANCE.getApi(OrderApiService::class.java, NetworkApi.Companion.SERVER_URL)
}